/**
 * @author YangTao
 * @date 2025/4/18
 */
package com.tian.source.controller;

import com.tian.core.beans.ResultBean;
import com.tian.source.model.User;
import com.tian.source.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * @author YangTao
 * @date 2025/4/18
 */
@Controller
public class loginController {

    @Autowired
    private UserService userService;

    @PostMapping("/userLogin")
    @ResponseBody
    public ResultBean<Map<String,Object>> login(User user, HttpServletRequest request){
        User userVO = userService.login(user);
        request.getSession().setAttribute("session_user",userVO);
        Map<String,Object> map = new HashMap<>();
        map.put("user",userVO);
        map.put("msg","登录成功");
        return new ResultBean<>(map);
    }
}
